package fr.efrei.tradesys.struts.actions.currencies;

import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;

import org.apache.commons.beanutils.BeanComparator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.opensymphony.xwork2.ActionSupport;

import fr.efrei.tradesys.hibernate.beans.Rate;
import fr.efrei.tradesys.hibernate.factory.DaoFactory;

public class RatesAction extends ActionSupport
{
	/**
	 * 
	 */
	private static final long	serialVersionUID	= 1L;
	private static Log				LOGGER						= LogFactory
																									.getLog(RatesAction.class);
	private List<Rate>				rates;
	private Comparator<Rate>	rateCurrency1Comp;
	private Comparator<Rate>	rateCurrency2Comp;

	@SuppressWarnings("unchecked")
	public String execute() throws Exception
	{
		LOGGER.info("Execution of " + this.getClass().getName());
		rates = new LinkedList<Rate>(DaoFactory.getInstance().getRateDao()
				.getLastRates());
		rateCurrency1Comp = new BeanComparator("currency1.code");
		rateCurrency2Comp = new BeanComparator("currency2.code");
		return SUCCESS;
	}

	public List<Rate> getRates()
	{
		return rates;
	}

	public void setRates(List<Rate> rates)
	{
		this.rates = rates;
	}

	public Comparator<Rate> getRateCurrency1Comp()
	{
		return rateCurrency1Comp;
	}

	public void setRateCurrency1Comp(Comparator<Rate> rateCurrency1Comp)
	{
		this.rateCurrency1Comp = rateCurrency1Comp;
	}

	public Comparator<Rate> getRateCurrency2Comp()
	{
		return rateCurrency2Comp;
	}

	public void setRateCurrency2Comp(Comparator<Rate> rateCurrency2Comp)
	{
		this.rateCurrency2Comp = rateCurrency2Comp;
	}

}
